package com.hsgene.discount.exception;

import com.hsgene.common.util.exception.ErrorCode;

/**
 * @desc:
 * @author: fuxiang
 * @date: 2018/8/14 17:01
 */
public enum DiscountErrorCode implements ErrorCode {

    COUPON_ALREADY_EXISTS(30001, "coupon_already_exists", "优惠券已存在"),
    OPERATION_FAILED(30002, "operation_failed", "操作失败");


    private final int code;

    private final String message;

    private final String description;

    DiscountErrorCode(int code, String message, String description) {
        this.code = code;
        this.message = message;
        this.description = description;
    }

    public static DiscountErrorCode getEnum(int code) {
        for (DiscountErrorCode sampleErrorCode : values()) {
            if (sampleErrorCode.code == code) {
                return sampleErrorCode;
            }
        }
        throw new IllegalArgumentException("No element matches " + code);
    }

    @Override
    public int getCode() {
        return code;
    }

    @Override
    public String getMessage() {
        return message;
    }

    @Override
    public String getDescription() {
        return description;
    }
}
